﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using RentalSystem.Data.EF;
using Web.Helper;

namespace Web.Models
{
    public class User
    {
        public string Guid { get; set; }
        public string CustomerGuid { get; set; }
        public long RoleId { get; set; }
        public string Email { get; set; }
        public string Password { get; set; }
        public DateTime DateCreated { get; set; }
        public string DisplayName { get; set; }
        public IPAddress LastLoginIp { get; set; }
        public DateTime? LastLoginDate { get; set; }
        public string WorkerGuid { get; set; }
        public AccountType Type { get; set; }
        public int? Discount { get; set; }

        public bool IsWorker
        {
            get
            {
                if (RoleId == 1)
                    return false;
                return true;
            }
        }

        public User()
        {

        }

        public User(Users model)
        {
            this.Guid = model.UserGuid;
            this.CustomerGuid = model.CustomerGuid;
            this.RoleId = model.UserRoleID;
            this.Email = model.UserEmail;
            this.Password = model.UserPassword;
            this.DateCreated = model.UserDateCreated;
            this.DisplayName = model.UserDisplayName;
            this.Type = (AccountType)model.Customers.CustomerTypes.CustomerTypeID;
            this.Discount = model.Customers.CustomerTypes.CustomerDiscount;

            if(model.UserLastLoginIP.HasValue)
                this.LastLoginIp = new IPAddress(model.UserLastLoginIP.Value);

            if(model.UserLastLoginDate.HasValue)
                this.LastLoginDate = model.UserLastLoginDate.Value;
        }
    }
}